﻿using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Options;

namespace K9Nano.LayIM.Internal
{
    internal class ClaimBasedUserIdProvider : IUserIdProvider
    {
        private readonly string _userIdClaimType;

        public ClaimBasedUserIdProvider(IOptions<LayIMOptions> options)
        {
            _userIdClaimType = options.Value.UserIdentifierClaimType;
        }

        public string GetUserId(HubConnectionContext connection)
        {
            return connection.User?.FindFirst(_userIdClaimType)?.Value;
        }
    }
}